package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.domain.OrderDetail;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/order/submit")
    public ResultInfo order(@RequestBody Order order){//接收参数
        //调用service
        orderService.submit(order);
        //返回结果
        return ResultInfo.success();


    }
    //查看订单
    @GetMapping("/order/userPage")
    public ResultInfo showOrder(@RequestParam(value = "page" ,defaultValue = "1")Integer pageNum,
                                @RequestParam(value = "pageSize" ,defaultValue = "5")Integer pageSize){//接收参数
        //调用service查询
        Page<Order> orders=orderService.showOrder(pageNum,pageSize);
        //返回结果
        return ResultInfo.success(orders);

    }
    //退出登录
    @PostMapping("user/logout")
    public ResultInfo exit(){//接收参数
        //调用service
        orderService.exit();
        //返回结果
        return ResultInfo.success();
    }
}
